/**
 * 
 */
package br.com.pim.action;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import br.com.pim.connection.ConnectionFactory;
import br.com.pim.dao.EstoqueDAO;
import br.com.pim.dao.ProdutoDAO;

/**
 * @author douglas.peixoto
 *
 */
public class HomeAction extends DispatchAction {
	
	
	
	public ActionForward iniciar(ActionMapping mapping, ActionForm form,
			HttpServletRequest req, HttpServletResponse resp) throws Exception {
		
		Connection myConn = null;
		ProdutoDAO pDAO = null;
		EstoqueDAO eDAO = null;
		
			try{
				myConn = new ConnectionFactory().getConnectionMySQL();
				pDAO = new ProdutoDAO(myConn);
				eDAO = new EstoqueDAO(myConn);
				req.setAttribute("LISTA_PRODUTOS_ESTOQUE", eDAO.buscarEstoque());
				
				req.setAttribute("LISTA_PRODUTOS", pDAO.buscarTodos());
			}finally{
				myConn.close();
			}
		
		
		return mapping.getInputForward();
		
	}

}
